#ifndef __APP_BUFFER_H__
#define __APP_BUFFER_H__
#include "log/log.h"
#include "string.h"
#include "stdlib.h"
#include <pthread.h>

// 读/写（小/子）缓冲区
typedef struct
{
    char *ptr;
    int size; // 容器大小
    int len;  // 存储数据长度
} SubBuffer;

typedef struct
{
    SubBuffer *sub_buffers[2];
    int read_index;
    int write_index;
    pthread_mutex_t read_lock;  // 读锁
    pthread_mutex_t write_lock; // 写锁
} Buffer;

Buffer *App_Buffer_Init(int size);

void App_Buffer_Free(Buffer *buffer);

int App_Buffer_Read(Buffer *buffer, char *data_buff, int buff_size);

int App_Buffer_Write(Buffer *buffer, char *data, int len);

#endif /* __APP_BUFFER_H__ */
